/*
Copyright (C) 2010 
Author		  Oliver Schenk
Contact		  Oliver.Schenk76@gmail.com

This program is free software; you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.
This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; 
if not, see <http://www.gnu.org/licenses/>.
*/

<%@ page  language="java" import="java.util.*,java.text.*"%>
<%@ page import="java.net.MalformedURLException" %>
<%@ page import="java.net.URL" %>
<%@ page import="com.google.gdata.client.calendar.*" %>
<%@ page import="com.google.gdata.data.calendar.*" %>
<%@ page import="com.google.gdata.client.*" %>
<%@ page import="com.google.gdata.data.*" %>
<%@ page import="com.google.gdata.model.*" %>
<%@ page import="com.google.gdata.util.*" %>
<%@ page import="com.google.gdata.data.calendar.*" %>
<%@ page import="com.google.gdata.data.extensions.*" %>
<%@ page import="com.google.gdata.data.*" %>
<%@ page import="com.google.gdata.client.http.*" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="SelfBookingSystem.AdminValues" %>
<%@ page import="SelfBookingSystem.PMF" %>
<%!
public int nullIntconv(String inv)
{   
	int conv=0;
		
	try{
		conv=Integer.parseInt(inv);
	}
	catch(Exception e)
	{}
	return conv;
}

%>
<%
//Variablen and Format declaration
Boolean belegt = new Boolean(false);
SimpleDateFormat DayFormat = new SimpleDateFormat("dd.MM.");
SimpleDateFormat MonthFormat = new SimpleDateFormat("MM");
SimpleDateFormat YearFormat = new SimpleDateFormat("yyyy");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat TimeFormat = new SimpleDateFormat("HH:m");

String GoogleCalendarURL = new String();
String EmailAddress = new String();
String Password = new String();
String myTime = new String();
String myDate = new String();
String AppID = new String();
String BodyBackgroundColor = new String();

if(request.getParameter("AppID") != null){
	AppID = request.getParameter("AppID");
}else{
	//HttpServletResponse resp;
	//resp.sendRedirect("/Error.jsp");
	response.sendRedirect("/Error.jsp");
	AppID = "xxx";
}


myTime = request.getParameter("Time");
myDate = request.getParameter("Date");

System.out.println("Book-Appointment JSP: Time: " + myTime);
System.out.println("Book-Appointment JSP: Date: " + myDate);



Map<String, String> m = Selbstbucher.GetConfigurationValues.GetConfigurationValues(AppID);
GoogleCalendarURL = m.get("GoogleCalendarURL");
EmailAddress = m.get("EmailAddress");
Password = m.get("Password");
BodyBackgroundColor = m.get("BodyBackgroundColor");
   
URL feedUrl = new URL(GoogleCalendarURL);
CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials(EmailAddress, Password);		
	
%>
<html>
<head>
<title>How to create Calendar in JSP</title>
<script src="/JavaScript/JavaScript.js" type="text/javascript"></script>
</head>
<body bgcolor="<%=BodyBackgroundColor%>">
	<p>
	Termin buchen am <%=myDate%> um <%=myTime%>.</br>
	Bitte geben Sie folgende Informationen ein.
	</p>
    <form action="/BookAppointment?AppID=<%=AppID%>" onsubmit="return validateFormOnSubmit(this)" method="post">
    <p>Vorname: <input name="Firstname" type="text" size="30" maxlength="30"></p>
  	<p>Zuname: <input name="Surname" type="text" size="30" maxlength="40"></p>
    <p>E-Mail: <input name="Email" type="text" size="30" maxlength="30"></p>
  	<p>Telefon: <input name="Phone" type="text" size="30" maxlength="40"></p>
      
	  <input type="hidden" name="Date" value="<%=myDate%>">
	  <input type="hidden" name="Time" value="<%=myTime%>">
	  <input type="hidden" name="AppID" value="<%=AppID%>">
	  		  
      <div><input type="submit" value="Book Appointment" /></div>
    </form>


</body>
</html>
